package algotithm.weekendrace.春季赛.test2;

/**
 * @author zhouyanxiang
 * @Date 2021-04-2021/4/5-17:35
 */
public class Solution {
    public int orchestraLayout(int num, int xPos, int yPos) {
        int n = (num + 1) / 2;
        int x = Math.min(xPos + 1, num - xPos);
        int y = Math.min(yPos + 1, num - yPos);
        int i = Math.min(x, y);
        long start = (4L * (i - 1) * (num - 1) % 9 + 9 - 4L * (i - 1) * (i - 2) % 9) % 9;
        int cur = num - 1 - 2 * (i - 1);
        if (xPos + 1 == i) {
            return (int) ((start + yPos - (i - 1)) % 9 + 1);
        }
        if (num - yPos == i) {
            return (int) ((start + cur + xPos - (i - 1)) % 9 + 1);
        }
        if (num - xPos == i) {
            return (int) ((start + 2 * cur + (num - 1 - yPos) - (i - 1)) % 9 + 1);
        }
        return (int) ((start + 3 * cur + (num - 1 - xPos) - (i - 1)) % 9 + 1);
    }
}
